<?php

	include_once ("../configs/config.php");     //配置参数
	include_once ("../common/mysql.class.php");   //MySQL操作类
	include_once ("../common/action.class.php");   //MySQL操作类
	
	$user_id = $_COOKIE['user_id'];
	$db = new action($mydbhost, $mydbuser, $mydbpw, $mydbname, "temp_conn", $mydbcharset, $mydbtag); //实例化数据库类
	$page = $_POST['page'];
	$type = $_POST['type'];

	if($page<0){
		$page=0;
		print_r(-1);
		return;
	}

	$from = $page * $bottle_num_onepage;
	$bottle_list = $db->get_user_bottle($user_id,$type,$from,$bottle_num_onepage);
	$list_length = count($bottle_list);
	
	if($list_length == 0){
		print_r(-1);
		return;
	}
	$return_list = array();
	for($i=0;$i<$list_length;$i++){
		$bottle_id = $bottle_list[$i]['bottle_id'];
		$is_readed = $bottle_list[$i]['is_readed'];
		$need_prompt = $bottle_list[$i]['need_prompt'];
		if($need_prompt==1){
			$silent = 0;
		}else{
			$silent = 1;
		}
		
		$bottle_info = $db->get_bottle_info($bottle_id);
		if(count($bottle_info) == 0){
			echo -1;
			return;
		}
		$head_img 	= $bottle_info['sender_info']['head'];
		$author 	= $bottle_info['sender_info']['nickname'];
		$message	= $bottle_info['last_message'];
		$time		= $bottle_info['last_message_time'];
		
		
		$return_list[$i]['bottle_id'] 		= $bottle_id;
		$return_list[$i]['head_img'] 		= $head_img;
		$return_list[$i]['message_date'] 	= $time;
		$return_list[$i]['author'] 			= $author;
		$return_list[$i]['message'] 		= $message;
		$return_list[$i]['is_read']			= $is_readed;
		$return_list[$i]['silent']			= $silent;
	}

	if($page<0) $page=0;

	$return_array = array('page'=>$page,'bottle_list'=>$return_list);
	print_r(json_encode($return_array)); 

?>
